﻿/* 
 *     This file is part of Kuka-KR3 Rubik's Cube Solver.
 *
 *    Kuka-KR3 Rubik's Cube Solver is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    Foobar is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details .
 *
 *    You should have received a copy of the GNU General Public License
 *    along with Kuka-KR3 Rubik's Cube Solver.  If not, see <http://www.gnu.org/licenses/>.
 *    
 * 
 */



using System;
using System.Collections.Generic;
using System.Text;

namespace CubeCalculations
{  
   public class CubeModel<T>
   {
      private T[] tCube = new T[6];
      private T[] TmpCube = new T[6];

      public T[] Cube
      {
         get
         {
            return tCube;
         }
      }

      public CubeModel(T[] Cube)
      {
         Array.Copy(Cube, this.tCube, Cube.Length);
      }
      public CubeModel(T Front,
         T Right,
         T Back,
         T Left,
         T Top,
         T Bottom)
      {
         tCube[(int)CubeSides.Front] = Front;
         tCube[(int)CubeSides.Right] = Right;
         tCube[(int)CubeSides.Back] = Back;
         tCube[(int)CubeSides.Left] = Left;
         tCube[(int)CubeSides.Top] = Top;
         tCube[(int)CubeSides.Bottom] = Bottom;
      }

      public CubeSides FindSide(T Side)
      {
         for (int i = 0; i < tCube.Length; i++)
         {
            if (tCube[i].Equals(Side))
               return (CubeSides)i;
         }
         throw new Exception("Side is not part of the Cube");
      }
      public void TurnRight()
      {
         //Aktuellen Würfel Speichern
         Array.Copy(tCube, TmpCube, tCube.Length);   

         //Front to Right
         tCube[(int)CubeSides.Right] = TmpCube[(int)CubeSides.Front];

         //Right to Back
         tCube[(int)CubeSides.Back] = TmpCube[(int)CubeSides.Right];

         //Back to Left
         tCube[(int)CubeSides.Left] = TmpCube[(int)CubeSides.Back];

         //Left to Front
         tCube[(int)CubeSides.Front] = TmpCube[(int)CubeSides.Left];
      }
      public void TurnLeft()
      {
         //Aktuellen Würfel Speichern
         Array.Copy(tCube, TmpCube, tCube.Length);

         //Back to Right
         tCube[(int)CubeSides.Right] = TmpCube[(int)CubeSides.Back];

         //Left to Back
         tCube[(int)CubeSides.Back] = TmpCube[(int)CubeSides.Left];

         //Front to Left
         tCube[(int)CubeSides.Left] = TmpCube[(int)CubeSides.Front];

         //Right to Front
         tCube[(int)CubeSides.Front] = TmpCube[(int)CubeSides.Right];
      }

      public void TurnUp()
      {
         //Aktuellen Würfel Speichern
         Array.Copy(tCube, TmpCube, tCube.Length);

         //Front to Top
         tCube[(int)CubeSides.Top] = TmpCube[(int)CubeSides.Front];

         //Top to Back
         tCube[(int)CubeSides.Back] = TmpCube[(int)CubeSides.Top];

         //Back to Bottom
         tCube[(int)CubeSides.Bottom] = TmpCube[(int)CubeSides.Back];

         //Bottom to Front
         tCube[(int)CubeSides.Front] = TmpCube[(int)CubeSides.Bottom];
      }

      public void TurnDown()
      {
         //Aktuellen Würfel Speichern
         Array.Copy(tCube, TmpCube, tCube.Length);

         //Front to Bottom
         tCube[(int)CubeSides.Bottom] = TmpCube[(int)CubeSides.Front];

         //Bottom to Back
         tCube[(int)CubeSides.Back] = TmpCube[(int)CubeSides.Bottom];

         //Back to Top
         tCube[(int)CubeSides.Top] = TmpCube[(int)CubeSides.Back];

         //Top to Front
         tCube[(int)CubeSides.Front] = TmpCube[(int)CubeSides.Top];
      }

      public void RotateLeft()
      {
         //Aktuellen Würfel Speichern
         Array.Copy(tCube, TmpCube, tCube.Length);

         //Top to Left
         tCube[(int)CubeSides.Left] = TmpCube[(int)CubeSides.Top];

         //Left to Bottom
         tCube[(int)CubeSides.Bottom] = TmpCube[(int)CubeSides.Left];

         //Bottom to Right
         tCube[(int)CubeSides.Right] = TmpCube[(int)CubeSides.Bottom];

         //Right to Top
         tCube[(int)CubeSides.Top] = TmpCube[(int)CubeSides.Right];
      }

      public void RotateRight()
      {
         //Aktuellen Würfel Speichern
         Array.Copy(tCube, TmpCube, tCube.Length);

         //Top to Right
         tCube[(int)CubeSides.Right] = TmpCube[(int)CubeSides.Top];

         //Right to Bottom
         tCube[(int)CubeSides.Bottom] = TmpCube[(int)CubeSides.Right];

         //Bottom to Left
         tCube[(int)CubeSides.Left] = TmpCube[(int)CubeSides.Bottom];

         //Left to Top
         tCube[(int)CubeSides.Top] = TmpCube[(int)CubeSides.Left];
      }
   }
}
